package com.uchonor.api.core.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.uchonor.api.core.entity.InterfaceConfig;
import com.uchonor.api.core.entity.InterfaceParameterConfig;
import com.uchonor.api.core.service.InterfaceConfigService;
import com.uchonor.api.core.service.InterfaceParameterConfigService;
import com.uchonor.olight.agent.annotation.Server;
import com.uchonor.olight.agent.annotation.web.*;
import com.uchonor.olight.agent.module.web.BaseDatagridController;
import com.uchonor.olight.agent.module.web.vo.RspResult;
import com.uchonor.olight.agent.module.web.vo.ServiceResult;
import com.uchonor.olight.agent.module.web.vo.StatusCode;

@Server(path = "/interfaceParameterConfig")
public class InterfaceParameterConfigController extends BaseDatagridController<InterfaceParameterConfigService, InterfaceParameterConfig> {

    /**
     * 根据interfaceId获取对应的接口信息
     * @param interfaceId
     * @return
     */
    @Get(path = "/getListByInterfaceId")
    public ServiceResult getListByInterfaceId(@RequestParam(name = "interfaceId") String interfaceId){
        ServiceResult sr = new ServiceResult();
        RspResult rr = new RspResult();
        try {
            rr.setDATA(this.baseService.getListByInterfaceId(interfaceId));
        } catch (Exception e) {
            rr.setRSP_DESC(e.getMessage());
            rr.setRSP_CODE(StatusCode.CODE_3000.getKey());
        }
        sr.setRSP(rr);
        return sr;
    }

    @Post(path = "/saveInterfaceParameterConfig")
    public ServiceResult saveInterfaceParameterConfig(@RequestBody InterfaceParameterConfig interfaceParameterConfig){
        ServiceResult sr = new ServiceResult();
        RspResult rr = new RspResult();
        try {
            setCreateUser(interfaceParameterConfig);
            rr.setDATA(this.baseService.saveOrUpdate(interfaceParameterConfig));
        } catch (Exception e) {
            rr.setRSP_DESC(e.getMessage());
            rr.setRSP_CODE(StatusCode.CODE_3000.getKey());
        }
        sr.setRSP(rr);
        return sr;
    }

    @Delete(path = "/deleteInterfaceParameterConfig")
    public ServiceResult deleteInterfaceParameterConfig(@RequestParam(name="parameterId") String parameterId){
        ServiceResult sr = new ServiceResult();
        RspResult rr = new RspResult();
        try {
            rr.setDATA(this.baseService.removeById(parameterId));
        } catch (Exception e) {
            rr.setRSP_DESC(e.getMessage());
            rr.setRSP_CODE(StatusCode.CODE_3000.getKey());
        }
        sr.setRSP(rr);
        return sr;
    }

}
